from pathlib import Path

# 目标目录
dir_path = Path(r"E:\手机备份\DCIM\Camera\三星")

# 遍历目录中的所有文件
for filename in dir_path.glob('*'):
    # 检查文件是否为.jpg或.mp4文件
    if filename.suffix in ['.jpg', '.mp4']:
        # 检查文件名是否需要修改
        if (filename.suffix == '.jpg' and not filename.stem.startswith('IMG_')) or \
           (filename.suffix == '.mp4' and not filename.stem.startswith('VID_')):
            # 构建新文件名
            new_filename = f'{("IMG_" if filename.suffix == ".jpg" else "VID_")}{filename.stem}{filename.suffix}'
            # 构建旧文件和新文件的完整路径
            old_file_path = filename
            new_file_path = dir_path / new_filename
            # 重命名文件
            old_file_path.rename(new_file_path)